<?php
$CI = & get_instance();
?>

<script>    
    dojo.ready(function() {
        sendForm('<?php echo $form_id?>');
    });    
</script>

<form id="form_<?php echo $form_id;?>" dojoType="dijit.form.Form">
    <div id="title_content"><?php echo $form_config['form_title'] ?></div>
    <table width="99%" cellspacing="10" class="myForm">
        <?php foreach ($models as $model => $m): ?>
            <?php if ($form_id == $m['form_id']) : ?>    
                <?php foreach ($m['fields'] as $field): ?>
                    <?php
                    $format = $m['dojo_fields'][$field]['format'];
                    $label_key = isset($m['dojo_fields'][$field]['label_key']) ? $m['dojo_fields'][$field]['label_key'] : '';
                    $prop = isset($m['dojo_fields'][$field]['dojo_props']) ? ', ' . $m['dojo_fields'][$field]['dojo_props'] : '';
                    $div_id = $field . '_' . $m['form_id'];
                    ?>            
                    <tr>
                        <td width="<?php echo $form_config['left_width'] ?>"><?php echo $label_key ?></td>
                        <td>

                            <?php if ($format == TYPE_TEXT): ?>

                                <input data-dojo-type=dijit.form.TextBox id="<?php echo $div_id ?>"
                                       data-dojo-props='name:"<?php echo $div_id ?>",type:"text"<?php echo $prop ?>'/>

                            <?php elseif ($format == TYPE_TEXTAREA): ?>
                                <input type="hidden" id="<?php echo $div_id ?>" name="<?php echo $div_id ?>" />
                                <div data-dojo-type="dijit.Editor" id="<?php echo $div_id ?>" name="<?php echo $div_id ?>"
                                     data-dojo-props='extraPlugins:["viewsource"]<?php echo $prop ?>'/>                                   

                                <script type="dojo/method" data-dojo-event="onChange">
                                      dojo.byId('<?php echo $div_id ?>').value = this.getValue();                                                                          
                                </script>                                                                
                                </div>                                    
                            <?php elseif ($format == TYPE_SELECT): ?>           


                                <div data-dojo-id="<?php echo $div_id ?>_store" data-dojo-type="dojo.data.ItemFileReadStore" data-dojo-props='url:"<?php echo $ajax_link . '/get_store_select/' . $model . '/' . $field ?>"'></div>
                                <select id="<?php echo $div_id ?>" data-dojo-type="dijit.form.FilteringSelect" 
                                       data-dojo-props='store:<?php echo $div_id ?>_store,                        
                                       name:"<?php echo $div_id ?>", 
                                       searchAttr:"name",                                       
                                       autoComplete:false<?php echo $prop ?>'/>
                                </select>                                         

                            <?php elseif ($format == TYPE_RADIO): ?>

                                <?php foreach ($m['dojo_fields'][$field]['options'] as $value => $lang_key): ?>    
                                    <input type="radio" name="<?php echo $div_id ?>" id="<?php echo $div_id . '_' . $value ?>" value="<?php echo $lang_key ?>"/>
                                    <label for="<?php echo $div_id . '_' . $value ?>"><?php echo $lang_key ?></label>        
                                <?php endforeach; ?>        

                            <?php elseif ($format == TYPE_CHECKBOX): ?>    

                                <?php if (isset($m['dojo_fields'][$field]['options'])): ?>
                                    <?php foreach ($m['dojo_fields'][$field]['options'] as $value => $lang_key): ?>
                                        <input id="<?php echo $div_id . '_' . $value ?>"
                                               data-dojo-type="dijit.form.CheckBox"
                                               data-dojo-props='name:"<?php echo $div_id . '_' . $value ?>"'/>
                                        <label for="<?php echo $div_id . '_' . $value ?>"><?php echo $lang_key ?></label>
                                    <?php endforeach; ?>

                                <?php elseif (isset($m['dojo_fields'][$field][''])): ?>

                                <?php endif; ?>

                            <?php elseif ($format == TYPE_DATETIME): ?>
                                <input id="<?php echo $div_id ?>" 
                                       data-dojo-type="dijit.form.DateTextBox" 
                                       data-dojo-props='name:"<?php echo $div_id ?>", type:"text"<?php echo $prop ?>'/>        

                            <?php elseif ($format == TYPE_CURRENCY): ?>
                                <input data-dojo-type=dijit.form.CurrencyTextBox name="<?php echo $div_id ?>" id="<?php echo $div_id ?>"
                                       data-dojo-props='name:"<?php echo $div_id ?>", type:"text"<?php echo $prop ?>'/>                         

                            <?php endif; ?>                
                        </td>
                    </tr>            

                <?php endforeach; ?>    

            <?php endif; ?>
        <?php endforeach; ?>

        <?php if ($form_config['button'] > 0): ?>
            <tr>
                <td><label></label></td>
                <td >                    
                    <?php if (($form_config['button'] & BTN_OK) > 0): ?>
                        <button data-dojo-type="dijit.form.Button"                                 
                                data-dojo-props='name:"submit_<?php echo $form_id; ?>", value:"submit_<?php echo $form_id; ?>", type:"submit",iconClass:"plusIcon"'>Ok</button>                                             
                        <?php endif; ?>
                    <?php if (($form_config['button'] & BTN_CANCEL) > 0): ?>
                        <button dojoType=dijit.form.Button  iconClass="delButtonIcon" >Cancel</button>
                    <?php endif; ?>
                </td>				
            </tr>
        <?php endif; ?>                
    </table>

</form>